package com.leff.cards.request;

import org.json.simple.JSONObject;

import com.leff.cards.Dictionary;

public class RequestResult {
	
	public int err;
	public Dictionary res;

	public RequestResult() {
		err = 1;
		res = new Dictionary();
	}
	
	public boolean isSuccessful() {
		return err >= 0;
	}
	public void setErrorResult(String message) {
		err = -1;
		res = Dictionary.withObject("reason", message);
	}
	public void setSuccessMessage(String message) {
		err = 1;
		res = Dictionary.withObject("message", message);
	}
	
	public Object getJson() {
		
		Dictionary resp = new Dictionary();
		resp.put("err", err);
		resp.put("res", res);
		return resp;
	}
	
	public String getJSONString() {
		
		Dictionary resp = new Dictionary();
		resp.put("err", err);
		resp.put("res", JSONObject.toJSONString(res));
		
		return JSONObject.toJSONString(resp);
	}
}
